import sys
#add parent directory to path because python does not imports classes on the higher directory level
sys.path.append("..")

from lolcut.main import Setup
#from lolcut.main import Setup

class FileFormat():
    def get_output_codec(self,input_extention):
        """Returns correct  codec for the given input codec"""
        input_pattern= "__output_"+input_extention+"_codec__"
        print "search for codec "+input_pattern
        print Setup().get_keys(self.get_file_type())
        for codec in Setup().get_keys(self.get_file_type()):
            if input_pattern in codec:
                print "there is a special codec pattern found for input extention "+input_extention
                return Setup().get_value(self.get_file_type(),input_pattern)
        
        #return common codec if there are no any special codecs found
        return  Setup().get_value(self.get_file_type(),"__output_all_codec__")
    
    def get_value(self,section,key):
        return Setup().get_value(section,key)
    def get_boolean_value(self,section,key):
        return Setup().get_boolean_value(section,key)
    
    def escape_string(self,string):
     return '%s' % (string.replace('\\', '\\\\').
                    replace(' ', '\\ ').
                    replace('(', '\(').
                    replace(')', '\)').
                    replace(',', '\,').
                    replace('"', '\"').
                    replace('$', '\$').
                    replace('&', '\&').
                    replace('!', '\!').
                    replace('`', '\`').
                    replace("'", "\\'"))
